cmake_minimum_required(VERSION 3.10)
project(yolo)

enable_language(CUDA)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_BUILD_TYPE "Release")
set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})

find_package(CUDA REQUIRED)
find_package(OpenCV 4 REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(message_filters REQUIRED)
find_package(yaml-cpp REQUIRED)

# TensorRT setup
if(${arch}     STREQUAL  "aarch64")
  set(tensorrt_include /usr/include/aarch64-linux-gnu)
  set(tensorrt_lib /usr/lib/aarch64-linux-gnu)
  set(cuda_lib /usr/local/cuda/lib64)
elseif(${arch} STREQUAL "x86_64")
  set(TENSORRT_ROOT         /home/xd/TensorRT-8.5.1.7.Linux.x86_64-gnu.cuda-11.8.cudnn8.6/TensorRT-8.5.1.7)
  set(cuda_lib /usr/local/cuda/lib64)
  set(tensorrt_include ${TENSORRT_ROOT}/include)
  set(tensorrt_lib     ${TENSORRT_ROOT}/lib)
endif()

include_directories(
  ${CUDA_INCLUDE_DIRS}
  ${tensorrt_include}
  ${cv_bridge_INCLUDE_DIRS}
  ${message_filters_INCLUDE_DIRS}
  ./include/
  ../../messages/devel/include/
)

link_directories(
  ${cuda_lib}
  ${tensorrt_lib}
)

add_executable(${PROJECT_NAME} 
  src/main.cpp 
  include/ToolFunction.hpp 
  src/ToolFunction.cpp
)

target_compile_options(${PROJECT_NAME} PRIVATE 
  $<$<CONFIG:Release>:-O3 -std=c++14 -Wextra -Wall -Wno-missing-field-initializers -Wno-deprecated-declarations -DENABLE_TEXT_BACKEND_STB -Wno-unused-parameter>
  $<$<CONFIG:Debug>:-O0 -g -std=c++14 -DENABLE_TEXT_BACKEND_STB>
)

target_link_libraries(${PROJECT_NAME}
  cudart
  cublasLt
  nvinfer
  nvinfer_plugin
  ${cv_bridge_LIBRARIES}
  ${message_filters_LIBRARIES}
  ${OpenCV_LIBS}
  ${YAML_CPP_LIBRARIES}
)



find_package(catkin REQUIRED COMPONENTS
  roscpp
  visualization_msgs
)

include_directories(
${roscpp_INCLUDE_DIRS}
../../messages/devel/include
)

target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})
